package com.yourname.lab4.v1;

public class Expression {
    private int left;
    private int right;
    private char operator;

    public Expression(int left, int right, char operator) {
        this.left = left;
        this.right = right;
        this.operator = operator;
    }

    public int getLeft() { return left; }
    public int getRight() { return right; }
    public char getOperator() { return operator; }

    public int calculate() {
        switch (operator) {
            case '+':
                return left + right;
            case '-':
                return left - right;
            default:
                throw new IllegalArgumentException("不支持的运算符: " + operator);
        }
    }

    @Override
    public String toString() {
        return left + " " + operator + " " + right + " = ";
    }
}